package com.wfx.controller;


import com.wfx.entity.CmsContentCat;
import com.wfx.entity.PageDTO;
import com.wfx.entity.PageResult;
import com.wfx.entity.Result;
import com.wfx.service.ICmsContentCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 内容分类 前端控制器
 * </p>
 *
 * @author zhu
 * @since 2021-01-23
 */
@RestController
@RequestMapping("/cmsContentCat")
@CrossOrigin
public class CmsContentCatController {

    @Autowired 
    private ICmsContentCatService iCmsContentCatService;

    //分页条件搜索
    @RequestMapping("/search")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public PageResult<CmsContentCat> search(@RequestBody PageDTO<CmsContentCat> pageDTO){
       return iCmsContentCatService.search(pageDTO);
    };


    //修改和添加
    @RequestMapping("/upAndAdd")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result upAndAdd(@RequestBody CmsContentCat cmsContentCat){
        return iCmsContentCatService.upAndAdd(cmsContentCat);
    };

    //删除
    @RequestMapping("/del")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result del(@RequestBody List<String> ids){
        return iCmsContentCatService.del(ids);
    };
    //所有分类
    @RequestMapping("/getAll")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result getAll(){
        return iCmsContentCatService.getAll();
    }

}
